@using Variant = MudBlazor.Variant
@using Elsa.Api.Client.Resources.StorageDrivers.Models
@using Elsa.Api.Client.Resources.VariableTypes.Models
@inherits StudioComponentBase

<MudDialog>
    <DialogContent>
        <EditForm EditContext="_editContext" OnValidSubmit="OnValidSubmit">
            <FluentValidationValidator @ref="_fluentValidationValidator" Validator="_validator" DisableAssemblyScanning="true"/>
            <MudStack>
                <MudField Label="Id" HelperText="The ID of the variable." Variant="Variant.Outlined">@_model.Id</MudField>
                <MudTextField Label="Name" @bind-Value="_model.Name" For="@(() => _model.Name)" HelperText="The name of the variable." Variant="Variant.Outlined"/>
                <MudSelectExtended T="VariableTypeDescriptor" @bind-Value="_model.VariableType" ToStringFunc="@(x => x?.DisplayName!)" Variant="Variant.Outlined" Label="Type" Dense="false" Margin="Margin.Normal">
                    @foreach (var grouping in _groupedVariableTypes)
                    {
                        <MudSelectItemGroupExtended T="string" Text="@grouping.Key">
                            @foreach (var variableType in grouping)
                            {
                                <MudSelectItemExtended T="VariableTypeDescriptor" Value="@variableType">@variableType.DisplayName</MudSelectItemExtended>
                            }
                        </MudSelectItemGroupExtended>
                    }
                </MudSelectExtended>
                <MudField Variant="Variant.Outlined" Label="Is array" HelperText="Check this option if the variable holds an array of the selected type.">
                    <MudCheckBox T="bool" @bind-Value="_model.IsArray" Label="This variable is an array"></MudCheckBox>
                </MudField>
                <MudTextField Label="Default value" @bind-Value="_model.DefaultValue" HelperText="A default value." Variant="Variant.Outlined"/>
                <MudSelect T="StorageDriverDescriptor" @bind-Value="_model.StorageDriver" ToStringFunc="@(x => x?.DisplayName!)" Variant="Variant.Outlined" Dense="false" Label="Storage">
                    @foreach (var storageDriver in _storageDriverDescriptors)
                    {
                        <MudSelectItem T="StorageDriverDescriptor" Value="@storageDriver">@storageDriver.DisplayName</MudSelectItem>
                    }
                </MudSelect>
            </MudStack>
        </EditForm>
    </DialogContent>
    <DialogActions>
        <MudButton OnClick="OnCancelClicked">Cancel</MudButton>
        <MudButton Color="Color.Primary" OnClick="OnSubmitClicked">Ok</MudButton>
    </DialogActions>
</MudDialog>